<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="sha1.js"></script>
<script>
    function get_sign(params, data, tiems) {
        var length = params.length;
        var param = "";
        params.forEach(function( val, index ) {
            console.log( val, index, this );
            param += val + "=" + data[val] + "&";
        });
        param = param.substr(0,(param.length-1))
        var hash = hex_sha1(data[params[0]]+param + tiems + data[params[length-1]]);

        return hash;
    }
    function rc4(data, pwd)//$pwd密钥　$data需加密字符串
    {
        var key = [''];
        var box = [''];
        var pwd_length = pwd.length;
        var data_length = data.length;
        for (var i = 0; i < 256; i++)
        {
            key[i] = ord($pwd[$i % $pwd_length]);
            box[i] = i;
        }
        for ($j = $i = 0; $i < 256; $i++)
        {
            $j = ($j + $box[$i] + $key[$i]) % 256;
            $tmp = $box[$i];
            $box[$i] = $box[$j];
            $box[$j] = $tmp;
        }
        $cipher = '';
        for ($a = $j = $i = 0; $i < $data_length; $i++)
        {
            $a = ($a + 1) % 256;
            $j = ($j + $box[$a]) % 256;
            $tmp = $box[$a];
            $box[$a] = $box[$j];
            $box[$j] = $tmp;
            $k = $box[(($box[$a] + $box[$j]) % 256)];
            $cipher .= chr(ord($data[$i]) ^ $k);
        }
        return $cipher;
    }


    var params = []
    params['token'] = '123122211sdfs'
    params['type'] = '1'
    var r = get_sign(['token', 'type'], params, '1522654074')
    console.log(r)
</script>
</html>